package com.example.springbootdemo.web;

import com.example.springbootdemo.mapper.MyMapper;
import com.example.springbootdemo.vo.MyConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
public class IndexAction {

    @GetMapping("hello")
    public String hello(){
        return "Hello World!";
    }

    @Resource
    MyMapper myMapper;

    @Value("${upload.dir}")
    String uploadDir;

    @Value("${upload.web-path}")
    String webPath;

    @Value("${spring.application.name}")
    String appName;

    @Resource
    MyConfig myConfig;

    @GetMapping("toindex")
    public ModelAndView index(ModelAndView mav){
        final List<Map<String, Object>> cars = myMapper.selectCars();
        mav.addObject("cars",cars);
        mav.addObject("你好,工学院!");

        mav.addObject("appName", appName);
        mav.addObject("uploadDir", uploadDir);
        mav.addObject("myConfig", myConfig);
        mav.addObject("webPath", webPath);

        mav.setViewName("index");
        return mav;
    }


}
